using UIFramework.Window;
using UnityEngine;
using UnityEngine.UI;
using Utils;

namespace UIFramework.Examples
{
    public class PopupExampleWindowController : WindowController
    {
        [SerializeField] 
        private Image exampleImage = null;

        private int currentPopupExample;
        private Color originalColor;

        /// <summary>
        /// 本身根上是继承MonoBehaviour的，所以Awake这类的函数都能用
        /// </summary>
        protected override void Awake() 
        {
            base.Awake();
            originalColor = exampleImage.color;
        }

        /// <summary>
        /// 打开窗口
        /// </summary>
        public void UI_ShowPopup() 
        {
            Signals.Get<ShowConfirmationPopupSignal>().Dispatch(GetPopupData());
        }

        /// <summary>
        /// 打开历史记录测试窗口
        /// </summary>
        public void UI_ShowWindowOther()
        {
            Signals.Get<ShowTestWindowOtherSignal>().Dispatch();
        }

        /// <summary>
        /// 打开任务窗口
        /// </summary>
        public void UI_ShowTaskWindow()
        {
            Signals.Get<ShowTaskWindowSignal>().Dispatch();
        }

        private ConfirmationPopupProperties GetPopupData() 
        {
            ConfirmationPopupProperties testProps = null;
            
            switch (currentPopupExample) 
            {
                case 0:
                    testProps = new ConfirmationPopupProperties("标题测试", 
                        "点下按钮试试",
                        "明白");
                    break;
                case 1:
                    testProps = new ConfirmationPopupProperties("小测试", 
                        "随便选个颜色",
                        "蓝色", OnBlueSelected, 
                        "红色", OnRedSelected);
                    break;
                case 2:
                    testProps = new ConfirmationPopupProperties("恢复颜色",
                        "恢复成原来的颜色吧",
                        "好的", OnRevertColors);
                    break;
                case 3:
                    testProps = new ConfirmationPopupProperties("重置", 
                        "随便测一下", "重置");
                    break;
            }
            
            currentPopupExample++;
            if (currentPopupExample > 3) 
            {
                currentPopupExample = 0;
            }

            return testProps;
        }

        private void OnRevertColors() 
        {
            exampleImage.color = originalColor;
        }

        private void OnRedSelected() 
        {
            // exampleImage.color = new Color(253, 104, 93);
            exampleImage.color = Color.red;

        }

        private void OnBlueSelected() 
        {
            // exampleImage.color = new Color(74, 144, 244);
            exampleImage.color = Color.blue;

        }
    }
}